package com.fgchen.controller;

import com.fgchen.biz.AnimalBiz;
import com.fgchen.domain.study02.Animal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;

/**
 * Created by Administrator on 2018-04-08.
 */
@Controller
public class AnimalController {

    @Autowired
    private AnimalBiz animalBiz;

    @RequestMapping("/animal/insert")
    public String insert(String name, Integer age) {
        this.animalBiz.insert(name, age);
        return "redirect:/animals";
    }

    @ResponseBody
    @RequestMapping("/animals")
    public Collection<Animal> animals() {
        return this.animalBiz.findAll();
    }

    @ResponseBody
    @RequestMapping("/animal/{id}")
    public Animal animal(@PathVariable("id") Long id) {
        return this.animalBiz.get(id);
    }

}
